<?php
/**
 * @desc Benutzerverwaltung 
 */
class controller_auth
{
	/**
	 * @desc initialisiert Model / View zur späteren Verwendung 
	 */
	public function __construct()
	{
		$_SESSION['loginstatus'] = false;
		$this->_view  = view_system::getInstance();
	}

	public function indexAction()
	{
		$this->_view->setValue('content',self:: getFormLogin());
	}

	public function loginAction()
	{
		if(model_auth::getInstance()->validate())
		{
			$_SESSION['loginstatus'] = true;
			$this->_view->setValue('content','login');
		}
		else
		{
			$this->_view->setValue('content','fehler');
		}
	}

	public function logoutAction()
	{
		$_SESSION['loginstatus'] = false;
		$this->_view->setValue('content','logout');
	}

	public function getFormLogin()
	{
		$form = "<form method=\"post\" action=\"/auth/login\">\n";
		$form .= "<p>\n";
		$form .= "<label>Benutzername:</label>\n";
		$form .= "<input type=\"text\" name=\"username\" required=\"required\" />\n";
		$form .= "</p>\n";
		$form .= "<p>\n";
		$form .= "<label>Passwort:</label>\n";
		$form .= "<input type=\"password\" name=\"password\" required=\"required\" />\n";
		$form .= "</p>\n";
		$form .= "<p>\n";
		$form .= "<input type=\"submit\" />\n";
		$form .= "</p>\n";
		$form .= "</form>\n";

		return $form;
	}
}